package cc.mrbird.febs.accounting.service.template;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;

import java.util.LinkedHashMap;
import java.util.Map;

public class TemplateService {
    public static Boolean templateConfirmation(XSSFSheet sheetAt, Integer type) {
        boolean result = false;
        TemplateStrategy strategy = TemplateStrategyFactory.getStrategy(type);
        int startRow = sheetAt.getFirstRowNum() + strategy.getStartRowOffset();
        Map<Integer, String> indexMap = strategy.getIndexMap();

        XSSFRow row = sheetAt.getRow(startRow);
        // 判断excel格式和模板是否一致, true为不符合
        for (int i = 0; i < row.getLastCellNum(); i++) {
            if (indexMap.containsKey(i)) {
                try {
                    if (!row.getCell(i).getStringCellValue().equals(indexMap.get(i))) {
                        result = true;
                        break;
                    }
                } catch (Exception e) {
                    result = true;
                    break;
                }
            }
        }
        return result;
    }
}
